package com.homedo.odin.solution.enumcode.user;

import java.util.Arrays;
import lombok.Getter;

@Getter
public enum PayModeEnum {
    ALIPAY(32, "支付宝支付"),
    WEIXINPAY(28, "微信支付"),
    ON_LINE_UMS_PAY(19, "在线支付-银联对私"),
    HEBI_PAY(25, "河币支付");

    private Integer dbValue;
    private String displayValue;

    PayModeEnum(Integer key, String value) {
        this.displayValue = value;
        this.dbValue = key;
    }

    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(Integer dbValue) {
        return Arrays.stream(PayModeEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(PayModeEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }

    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(Integer dbValue) {
        return Arrays.stream(PayModeEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }

}
